﻿package mortal.game.view.platform.platformTencent
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PlatformQQModule extends BaseWindow
    {
        private var _clsVec:Vector.<Class>;
        private var _curSelView:PlatformTencentBasePanel;
        private var _curSelIndex:int = -1;
        private var _categorySpr:PlatformQQCategorySpr;

        public function PlatformQQModule(param1:ILayer = null)
        {
            super(param1);
            if (PlatformTencentUtil.isYellowEnter())
            {
                this.title = "QQ黄钻特权";
            }
            else if (PlatformTencentUtil.isBlueEnter())
            {
                this.title = "QQ蓝钻特权";
            }
            return;
        }// end function

        public function get curSelView() : GSprite
        {
            return this._curSelView;
        }// end function

        public function setDefaultPanel(param1:int = 0) : void
        {
            this._curSelIndex = param1;
            this.updatePanel();
            return;
        }// end function

        private function updatePanel() : void
        {
            var _loc_1:Class = null;
            var _loc_2:Object = null;
            if (this._curSelView && !this._curSelView.isDisposed)
            {
                this._curSelView.dispose();
            }
            for each (_loc_2 in PlatformQQConst.tagArr)
            {
                
                if (_loc_2["tagIndex"] == this._curSelIndex)
                {
                    _loc_1 = _loc_2["clsName"] as Class;
                    break;
                }
            }
            if (_loc_1)
            {
                this._curSelView = UICompomentPool.getUICompoment(_loc_1);
            }
            else
            {
                this._curSelView = UICompomentPool.getUICompoment(GSprite);
            }
            this._curSelView.x = 196;
            this._curSelView.y = 34;
            this.addChild(this._curSelView);
            this.refresh();
            return;
        }// end function

        private function onSwitchPanel(event:DataEvent) : void
        {
            var _loc_2:* = int(event.data);
            if (this._curSelIndex != _loc_2)
            {
                this._curSelIndex = _loc_2;
                this.updatePanel();
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            setSize(899 - 152, 613 - 30 - 61);
            this._categorySpr = UICompomentPool.getUICompoment(PlatformQQCategorySpr);
            this._categorySpr.x = 2;
            this._categorySpr.y = 30;
            addChild(this._categorySpr);
            Dispatcher.addEventListener(EventName.PlatformQQSwitchPanel, this.onSwitchPanel);
            if (PlatformTencentUtil.hasNewHandGiftReward())
            {
                this.switchTag(PlatformQQConst.Tag_B);
            }
            else if (PlatformTencentUtil.hasDailyVipReward() || PlatformTencentUtil.hasDailyLoginGiftReward() || PlatformTencentUtil.hasDailyDeluxeGiftReward())
            {
                this.switchTag(PlatformQQConst.Tag_C);
            }
            else if (PlatformTencentUtil.hasLevelGiftReward())
            {
                this.switchTag(PlatformQQConst.Tag_D);
            }
            else
            {
                this.switchTag(PlatformQQConst.Tag_A);
            }
            return;
        }// end function

        private function switchTag(param1:int) : void
        {
            if (this._categorySpr && !this._categorySpr.isDisposed)
            {
                this._categorySpr.switchTag(param1);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._curSelIndex = -1;
            this._categorySpr.dispose(param1);
            this._categorySpr = null;
            if (this._curSelView)
            {
                this._curSelView.dispose(param1);
                this._curSelView = null;
            }
            Dispatcher.removeEventListener(EventName.PlatformQQSwitchPanel, this.onSwitchPanel);
            super.disposeImpl(param1);
            return;
        }// end function

        public function refresh() : void
        {
            if (this._curSelView && !this._curSelView.isDisposed)
            {
                this._curSelView.refresh();
            }
            return;
        }// end function

    }
}
